package come.bite.spring.demo;

import ch.qos.logback.core.util.StringUtil;
import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/user")
@RestController
public class usercontroller {
    @RequestMapping("/login")
    public boolean login(String username, String password , HttpSession session) {
        //还未学习数据库的操作，暂时这样写死
        //参数校验
       /* if (username != null ||password ==" "|| password == null ||username =="") {
            return false;
        }*/
        if (!StringUtils.hasLength(username) ||!StringUtils.hasLength(password)) {
            return false;
        }
        //校验用户名和密码是否正确
        if ("admin".equals(username) &&"admin".equals(password)){
            session.setAttribute("username",username);
            return true;
        }
        return false;
    }


    @RequestMapping("/getLonginuser")
    public String getLonginuser(HttpSession session) {
        String username1 = (String) session.getAttribute("username");
        return username1;
    }
}
